package com.snow.useviewdemo.function2.hindicon;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.snow.useviewdemo.R;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by zhaoyingtao
 * Date: 2021/11/16
 * Describe:
 */
public class TestItemAdapter extends RecyclerView.Adapter<TestItemAdapter.ItemViewHolder> {
    private List<String> dataList;
    private Context mContext;

    public TestItemAdapter(List<String> dataList, Context mContext) {
        this.dataList = dataList;
        this.mContext = mContext;
    }

    @NonNull
    @NotNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adater_test_item_layout, null, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ItemViewHolder holder, int position) {
        String s = dataList.get(position);
        holder.tvName.setText(s);
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        public TextView tvName;

        public ItemViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tv_name);
        }
    }
}
